package com.huangpuweb.api.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.base.Charsets;
import com.huangpuweb.api.Constants;
import com.huangpuweb.api.model.*;
import com.huangpuweb.api.service.*;
import com.huangpuweb.api.util.*;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.LaxRedirectStrategy;
import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;
import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GlobalCoordinates;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.net.URI;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;


/**
 * 如风开发接口
 */
@Controller
@RequestMapping(value = "/rf")
public class RfController {

    private static Logger logger = Logger.getLogger(RfController.class);
    private LaoXiMenApiService laoXiMenApiService;

    @Autowired
    private GaApiService gaApiService;

    @Autowired
    public void setLaoXiMenApiService(LaoXiMenApiService laoXiMenApiService) {
        this.laoXiMenApiService = laoXiMenApiService;
    }

    private ApiService apiService;

    @Autowired
    public void setApiService(ApiService apiService) {
        this.apiService = apiService;
    }

    @Autowired
    private CrowdSituationApiService crowdSituationApiService;
    @Autowired
    private HiveZdk57ApiService hiveZdk57ApiService;
    @Autowired
    private NanDongApiService nanDongApiService;

    /**
     * 城市垃圾暴露点位
     */
    @RequestMapping(value = "/getCityRubbishExposed")
    public void getCityRubbishExposed(HttpServletResponse response) throws Exception {
        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        logger.info("------getCityRubbishExposed-----start-------");
        Integer dayCount = apiService.getCityRubbishExposedDayCount();
        Integer monthCount = apiService.getCityRubbishExposedMonthCount();
        Integer sum = apiService.getCityRubbishExposedSum();
        resultJson.put("dayCount", dayCount);
        resultJson.put("monthCount", monthCount);
        resultJson.put("sum", sum);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
        Date date = new Date();
        List<DiscoverDisposal> discoverDisposalCount = apiService.getCityRubbishExposedDiscoverDisposalCount(sdf.format(date));
        resultJson.put("discoverDisposal", discoverDisposalCount);
        resultJson.put("daySolve", 0);
        resultJson.put("monthSolve", 0);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), response);
    }

    /**
     * 根据季度获取电梯检查详情
     */
    @RequestMapping(value = "/getLXMElevatorExamineByQuarter")
    public void getLXMElevatorExamineByQuarter(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        logger.info("------getLXMElevatorExamineByQuarter-----start-------");
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);
        String quarter = reqjson.getString("quarter");
        //String quarter = new String(request.getParameter("quarter").getBytes("iso8859-1"),"UTF-8");

        List<LxmElevatorExamineInfo> lxmElevatorExamineInfos = laoXiMenApiService.getLXMElevatorExamineByQuarter(quarter);
        resultObj.put("data", lxmElevatorExamineInfos);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);
    }

    /**
     * 历年处罚
     */
    @RequestMapping(value = "/getLXMPunishmentList")
    public void getLXMPunishmentList(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        logger.info("------getLXMPunishmentList-----start-------");
        List<LxmElevatorPunishUnit> lxmElevatorPunishUnits = laoXiMenApiService.getLXMPunishmentList();
        resultObj.put("data", lxmElevatorPunishUnits);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);
    }

    /**
     * 2020年整改
     */
    @RequestMapping(value = "/getLXMRectifyList")
    public void getLXMRectifyList(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        logger.info("------getLXMRectifyList-----start-------");
        List<LxmElevatorRectifyUint> lxmElevatorPunishUnits = laoXiMenApiService.getLXMRectifyList();
        resultObj.put("data", lxmElevatorPunishUnits);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);

    }

    /**
     * 缩略图实现
     */
    @RequestMapping(value = "/getShopRecruitImageList")
    public void getShopRecruitImageList(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        logger.info("------getShopRecruitImageList-----start-------");
//        List<String> sysShopRecruitStreets = laoXiMenApiService.getShopRecruitImageList();
        List<String> sysShopRecruitStreets = crowdSituationApiService.getDZDPImageList();
        HttpGet get;
        for (String s : sysShopRecruitStreets) {
            get = new HttpGet("http://172.82.4.51:8080/images/" + s + ".jpg");
            get = new HttpGet(s);
            try {
                HttpClient httpClient = new DefaultHttpClient();
                String substring = s.substring(s.lastIndexOf("/") + 1, s.lastIndexOf("."));
                String imgPath = "E:\\test\\ddd\\" + substring + "_simple.jpg";
                HttpResponse response = httpClient.execute(get);
                HttpEntity entity = response.getEntity();
                InputStream inStream = entity.getContent();

                FileOutputStream fw = new FileOutputStream(imgPath);
                byte[] b = new byte[1024];
                int length;
                while ((length = inStream.read(b)) > 0) {
                    fw.write(b, 0, length);
                }
                fw.close();
//            EntityUtils.consume(entity);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {

            }
        }
//        resultObj.put("data", sysShopRecruitStreets);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);

    }

    /**
     * 电梯使用状态，电梯类别，电梯重点使用场所
     */
    @RequestMapping(value = "/getElevatorInfoByRule")
    public void getElevatorInfoByRule(HttpServletRequest req, HttpServletResponse resp) throws Exception {

        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        String str = getRequestBodyString(req);
        LogFactory.getLog(this.getClass()).info("------getElevatorInfoByRule-----start-------");
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);
        String useStatus = reqjson.getString("useStatus");
        String deviceType = reqjson.getString("deviceType");
        String deviceUsePlace = reqjson.getString("deviceUsePlace");
        List<LxmElevatorInfo> elevatorInfoList;
        if (useStatus != null && !useStatus.equals("")) {
            elevatorInfoList = laoXiMenApiService.getElevatorInfoByUseStatus(useStatus);
        } else if (deviceType != null && !deviceType.equals("")) {
            elevatorInfoList = laoXiMenApiService.getElevatorInfoByDeviceType(deviceType);
        } else if (deviceUsePlace != null && !deviceUsePlace.equals("")) {
            elevatorInfoList = laoXiMenApiService.getElevatorInfoByDeviceUsePlace(deviceUsePlace);
        } else {
            return;
        }
        for (LxmElevatorInfo ss : elevatorInfoList) {
            if (ss.getLat() != null && ss.getLat() != null) {
                double[] map = MapUtil.bd09towgs84(Double.parseDouble(ss.getLng()), Double.parseDouble(ss.getLat()));
                ss.setLng(map[0] + "");
                ss.setLat(map[1] + "");
            }
            //处理字符串日期格式，注意数据库脏数据判断
            if (ss.getTest_date() != null && !ss.getTest_date().equals("")) {
                ss.setTest_date(ss.getTest_date().substring(0, 10));
            }
            if (ss.getNext_test_date() != null && !ss.getNext_test_date().equals("")) {
                ss.setNext_test_date(ss.getNext_test_date().substring(0, 10));
            }
            if (ss.getNext_selftest_date() != null && !ss.getNext_selftest_date().equals("")) {
                ss.setNext_selftest_date(ss.getNext_selftest_date().substring(0, 10));
            }
            if (ss.getDevice_stop_date() != null && !ss.getDevice_stop_date().equals("")) {
                ss.setDevice_stop_date(ss.getDevice_stop_date().substring(0, 10));
            }
            if (ss.getManufacture_date() != null && !ss.getManufacture_date().equals("")) {
                ss.setManufacture_date(ss.getManufacture_date().substring(0, 10));
            }
            if (ss.getPutuse_date() != null && !ss.getPutuse_date().equals("")) {
                ss.setPutuse_date(ss.getPutuse_date().substring(0, 10));
            }
        }
        resultJson.put("listLxmSuperviseStrength", elevatorInfoList);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);

        return;
    }

    public static Map<String, String> map = new ConcurrentHashMap<>();


    /**
     * 年度景区累计客流
     */
    @RequestMapping("getEveryYearSpotData")
    public void getEveryYearSpotData(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        logger.info("------getEveryYearSpotData-----start-------");
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);
        String year = reqjson.getString("year");
//        long s=System.currentTimeMillis();
        List<AppCgjYearCount> stringList = hiveZdk57ApiService.getYearCountByYear(year);
//        System.out.println(System.currentTimeMillis()-s);
        for (AppCgjYearCount appCgjYearCount : stringList) {
            if (appCgjYearCount.getSpotcode().equals("豫园商城")) {
                appCgjYearCount.setSpotcode("YUYUAN_NEIQUAN");
            }
            if (appCgjYearCount.getSpotcode().equals("YUYUAN")) {
                appCgjYearCount.setSpotcode("YUYUAN_WAIQUAN");
            }
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("data", stringList);
        jsonObject.put("error_code", 0);
        jsonObject.put("error_msg", "获取成功");
        responseData(jsonObject.toString(), resp);
    }

    /**
     * 根据年 获取各个景区历史一级预警次数
     */

    @RequestMapping("getEveryYearSpotWarnCount")
    public void getEveryYearSpotWarnCount(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        logger.info("------getEveryYearSpotWarnCount-----start-------");
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);
        String year = reqjson.getString("year");
        //南京路年度一级预警总数
        EveryYearSpotWarnCount count = crowdSituationApiService.getAllDataRecordBackCount("SHHPQ_NANJINGLU", year);
        //南京东路预警峰值
        List<EveryYearSpotWarnCount> max = crowdSituationApiService.getAllDataRecordBackMax("SHHPQ_NANJINGLU", year);
        //年度各个景区累计一级预警数 TODO豫园股份的年度预警数
        List<EveryYearSpotWarnCount> everyYearSpotWarnCount = hiveZdk57ApiService.getEveryYearSpotWarnCount(year);
        if (count != null) {
            count.setInfo(max);
            everyYearSpotWarnCount.add(count);
        }

        //各个景区预警详情
        for (EveryYearSpotWarnCount warnInfo : everyYearSpotWarnCount) {
            List<EveryYearSpotWarnCount> infoList = hiveZdk57ApiService.getWarnCount(year, warnInfo.getSpotid());
            warnInfo.setInfo(infoList);
        }

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("data", everyYearSpotWarnCount);
        jsonObject.put("error_code", 0);
        jsonObject.put("error_msg", "获取成功");
        responseData(jsonObject.toString(), resp);
    }
    @Autowired
   private ShiGongAnQuanApiService shiGongAnQuanApiService;
    /**
     * 提供给华为接口-电招电牌总数
     */
    @RequestMapping(value = "/getHpDianZhaoDianPaiStreet")
    public void getHpDianZhaoDianPaiStreet(HttpServletRequest req, HttpServletResponse resp) throws Exception {

        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getHpDianZhaoDianPaiStreet-----start-------");
        //总数
        Integer streetCount = shiGongAnQuanApiService.getHpDianZhaoDianPaiStreetAllCount();
        Integer A = shiGongAnQuanApiService.getABC("A");
        Integer B = shiGongAnQuanApiService.getABC("B");
        Integer C = shiGongAnQuanApiService.getABC("C");
        //占比
        double APercent=Double.valueOf(A)/Double.valueOf(A+B+C);
        double BPercent=Double.valueOf(B)/Double.valueOf(A+B+C);
        double CPercent=Double.valueOf(C)/Double.valueOf(A+B+C);
        resultJson.put("shopSignCount", streetCount);
        resultJson.put("storeCount", 14682);
        resultJson.put("APercent", APercent);
        resultJson.put("BPercent", BPercent);
        resultJson.put("CPercent", CPercent);
        resultJson.put("A", A);
        resultJson.put("B", B);
        resultJson.put("C", C);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);

    }
    /**
     * 提供给华为接口-施工工地数据总览
     */
    @RequestMapping(value = "/getSysLargeBuildingData")
    public void getSysLargeBuildingData(HttpServletRequest req, HttpServletResponse resp) throws Exception {

        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getSysLargeBuildingData-----start-------");


        //大型工程总数
        Integer allcount = shiGongAnQuanApiService.getAllCount();
        //装饰装修项目
        Integer allTypeZcount = shiGongAnQuanApiService.getAllTypeCount("Z");

        //大型土建项目
        Integer allTypeTcount = shiGongAnQuanApiService.getAllTypeCount("t");
        //改造扩建项目
        Integer allTypeGcount = shiGongAnQuanApiService.getAllTypeCount("g");
        //1000万以上的项目
        Integer allType1000Zcount = shiGongAnQuanApiService.getAllTypeCount1000();
        //历年项目不分类
        Integer notypecount = shiGongAnQuanApiService.getImportCount("历年项目不分类");
        //特殊类建筑装饰装修工程
        Integer importcount = shiGongAnQuanApiService.getImportCount("特殊类建筑装饰装修工程");
        double importcountp = (double) importcount / allTypeZcount;
        double notypecountp = (double) notypecount / allTypeZcount;
        resultJson.put("importcountpercent", Math.round(importcountp * 100) + "%");
        resultJson.put("importcount", importcount);
        resultJson.put("notypecountpercent", Math.round(notypecountp * 100) + "%");
        resultJson.put("notypecount", notypecount);
        double noimportcountp = 1 - importcountp - notypecountp;
        resultJson.put("noimportcountpercent", Math.round(noimportcountp * 100) + "%");
        resultJson.put("noimportcount", allTypeZcount-importcount-notypecount);
        resultJson.put("allcount", allcount);
        resultJson.put("allTypeZcount", allTypeZcount);
        resultJson.put("allTypeTcount", allTypeTcount);
        resultJson.put("allTypeGcount", allTypeGcount);
        resultJson.put("blmq", 608);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", resultJson);
        responseData(resultObj.toString(), resp);

    }

    /**
     * 风景区总人次分析  获取景区 每年每月 人流总量
     */
    @RequestMapping("getEveryYearSpotAnalysis")
    public void getEveryYearSpotAnalysis(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject jsonObject = new JSONObject();
        logger.info("------getEveryYearSpotAnalysis-----start-------");
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);
        String year = reqjson.getString("year");

        List<YearSpotAnalysis> ss = crowdSituationApiService.getEveryYearSpotAnalysis(year);
        Map<String, List> yearSpotAnalyses = hiveZdk57ApiService.getEveryYearSpotAnalysis(year);
        yearSpotAnalyses.put("NANJINGLU", ss);
        jsonObject.put("data", yearSpotAnalyses);
        jsonObject.put("error_code", 0);
        jsonObject.put("error_msg", "获取成功");
        responseData(jsonObject.toString(), resp);
    }


    /**
     * 停车场数据
     */
    @RequestMapping("getParkInfoRealTimeData")
    public void getParkInfoRealTimeData(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        logger.info("------getParkInfoRealTimeData-----start-------");
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);
        String spotCode = reqjson.getString("spotCode");
        List<SysHpParkInfo> mapList = crowdSituationApiService.getParkInfoRealTimeData(spotCode);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("data", mapList);
        jsonObject.put("error_code", 0);
        jsonObject.put("error_msg", "获取成功");
        responseData(jsonObject.toString(), resp);

    }

    /**
     * 停车场接口数据，原json数据不用
     */
    @RequestMapping("getParkInfo")
    public void getParkInfo(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        logger.info("------getParkInfoRealTimeData-----start-------");
        List<SysHpPark> mapList = crowdSituationApiService.getParkInfo();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("data", mapList);
        jsonObject.put("error_code", 0);
        jsonObject.put("error_msg", "获取成功");
        responseData(jsonObject.toString(), resp);

    }

    /**
     * 未来道路预测 废弃不用
     **/
    @RequestMapping("getRoadPredData")
    public void getRoadPredData(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        logger.info("------getRoadPredData-----start-------");
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject reqjson = JSONObject.parseObject(str);
        String roadName = reqjson.getString("roadName");
        List<SysHpRoadPreCondition> list = apiService.getRoadPredData(roadName);
        for (SysHpRoadPreCondition sysHpRoadPreCondition : list) {
            sysHpRoadPreCondition.setPredTime(sysHpRoadPreCondition.getPredTime().substring(8, 10));
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("data", list);
        jsonObject.put("error_code", 0);
        jsonObject.put("error_msg", "获取成功");
        responseData(jsonObject.toString(), resp);
    }

    /**
     * 周边路况信息
     */
    @RequestMapping("getSpotRoadInfoData")
    public void getSpotRoadInfoData(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        logger.info("------getSpotRoadInfoData-----start-------");
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONArray jsonArray = new JSONArray();
        JSONObject jo = new JSONObject();
        JSONObject jsonObject = null;
        JSONObject reqjson = JSONObject.parseObject(str);
        String spotCode = reqjson.getString("spotCode");
        List<SysHpRoadCondition> listSysHpRoad = crowdSituationApiService.getSysHpRoadConditionBySpotCode(spotCode);
        for (SysHpRoadCondition ss : listSysHpRoad) {
            jsonObject = new JSONObject();
            jsonObject.put("roadId", ss.getRoadId());
            jsonObject.put("coordinates", ss.getRoadCoordinate());
            jsonObject.put("roadName", ss.getInterName());
            SysHpRoadConditionInfo sr = crowdSituationApiService.getlistSysHpRoadConditionInfo(ss.getRoadId());
            if (sr != null) {
                Double _nostopSpeed = sr.getNostopSpeed();
                if (sr.getLen() != null) {
                    jsonObject.put("len", sr.getLen());
                } else {
                    jsonObject.put("len", 0);
                }
                if (sr.getNostop_travel_time() != null) {
                    jsonObject.put("nostop_travel_time", sr.getNostop_travel_time());
                } else {
                    jsonObject.put("nostop_travel_time", 0);
                }
                if (sr.getTravel_time() != null) {
                    jsonObject.put("travel_time", sr.getTravel_time());
                } else {
                    jsonObject.put("travel_time", 0);
                }
                if (_nostopSpeed != null) {
                    jsonObject.put("nostopSpeed", _nostopSpeed);
                    jsonObject.put("speed", sr.getSpeed());


                    //计算拥堵级别
                    //高速公路
                    if (sr.getRoadLevel() == 41000) {//高速
                        if (_nostopSpeed > 50) {//畅通
                            jsonObject.put("conges", "畅通");
                        } else if (30 <= _nostopSpeed && _nostopSpeed <= 50) {//缓行
                            jsonObject.put("conges", "缓行");
                        } else if (15 <= _nostopSpeed && _nostopSpeed < 30) {//拥堵
                            jsonObject.put("conges", "拥堵");
                        } else if (15 < _nostopSpeed) {//严重拥堵
                            jsonObject.put("conges", "严重拥堵");
                        }
                    } else if (sr.getRoadLevel() == 43000) {//快速路
                        if (_nostopSpeed > 40) {//畅通
                            jsonObject.put("conges", "畅通");
                        } else if (20 <= _nostopSpeed && _nostopSpeed <= 40) {//缓行
                            jsonObject.put("conges", "缓行");
                        } else if (10 <= _nostopSpeed && _nostopSpeed < 20) {//拥堵
                            jsonObject.put("conges", "拥堵");
                        } else if (10 < _nostopSpeed) {//严重拥堵
                            jsonObject.put("conges", "严重拥堵");
                        }
                    } else if (sr.getRoadLevel() == 44000) {//主要道路
                        if (_nostopSpeed > 25) {//畅通
                            jsonObject.put("conges", "畅通");
                        } else if (12 <= _nostopSpeed && _nostopSpeed <= 25) {//缓行
                            jsonObject.put("conges", "缓行");
                        } else if (5 <= _nostopSpeed && _nostopSpeed < 12) {//拥堵
                            jsonObject.put("conges", "拥堵");
                        } else if (5 < _nostopSpeed) {//严重拥堵
                            jsonObject.put("conges", "严重拥堵");
                        }
                    } else if (sr.getRoadLevel() == 45000) {//次要道路
                        if (_nostopSpeed > 20) {//畅通
                            jsonObject.put("conges", "畅通");
                        } else if (10 <= _nostopSpeed && _nostopSpeed <= 20) {//缓行
                            jsonObject.put("conges", "缓行");
                        } else if (5 <= _nostopSpeed && _nostopSpeed < 10) {//拥堵
                            jsonObject.put("conges", "拥堵");
                        } else if (5 < _nostopSpeed) {//严重拥堵
                            jsonObject.put("conges", "严重拥堵");
                        }
                    } else {
                        if (_nostopSpeed > 20) {//畅通
                            jsonObject.put("conges", "畅通");
                        } else if (10 <= _nostopSpeed && _nostopSpeed <= 15) {//缓行
                            jsonObject.put("conges", "缓行");
                        } else if (5 <= _nostopSpeed && _nostopSpeed < 10) {//拥堵
                            jsonObject.put("conges", "拥堵");
                        } else if (5 < _nostopSpeed) {//严重拥堵
                            jsonObject.put("conges", "严重拥堵");
                        }
                    }
                } else {
                    jsonObject.put("conges", "畅通");
                    jsonObject.put("nostopSpeed", 0);
                    jsonObject.put("speed", 0);
                }
            } else {
                jsonObject.put("conges", "畅通");
                jsonObject.put("nostopSpeed", 0);
                jsonObject.put("speed", 0);
                jsonObject.put("len", 0);
                jsonObject.put("nostop_travel_time", 0);
                jsonObject.put("travel_time", 0);
            }
            jsonArray.add(jsonObject);
        }
        jo.put("data", jsonArray);
        jo.put("error_code", 0);
        jo.put("error_msg", "获取成功");
        responseData(jo.toString(), resp);
    }

    @Autowired
    private PersonDataService personDataService;

    /**
     * 位置解析经纬度 todo
     */
    @Transactional
    @RequestMapping("getCoordinateByAddress")
    public void getCoordinateByAddress(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject jsonObject = new JSONObject();
        List<HpBasSyrkJzdz> bmxModelList = personDataService.getList();
        HttpClient client = new DefaultHttpClient();
        for (HpBasSyrkJzdz bmxModel : bmxModelList) {
            HttpGet get = new HttpGet("http://api.map.baidu.com/geocoder?address=上海市黄浦区" + bmxModel.getJzdz() + "&output=json&key=PyLa5E6K6BEGI0euwz1s9dWc");

            // 执行get请求，得到返回体
            HttpResponse response = client.execute(get);
            JSONObject jo = null;
            JSONObject jb = null;
            JSONObject locationjson = null;
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                // 解析数据
                String data = EntityUtils.toString(response.getEntity(), Charsets.UTF_8);
                if (null != data) {
                    jo = JSONObject.parseObject(data);
                    if (jo.get("status").equals("OK")) {
                        jb = jo.getJSONObject("result");
                        locationjson = jb.getJSONObject("location");
//                        System.out.println(bmxModel.getJzdz() + "----" + locationjson.getString("lng") + "------" + locationjson.getString("lat"));
                        double[] map = MapUtil.bd09towgs84(Double.valueOf(locationjson.getString("lng")), Double.valueOf(locationjson.getString("lat")));
                        personDataService.insert(String.valueOf(map[0]), String.valueOf(map[1]), bmxModel.getId());
                    }
                }
            }
        }
        jsonObject.put("data", "");
        jsonObject.put("error_code", 0);
        jsonObject.put("error_msg", "获取成功");
        responseData(jsonObject.toString(), resp);
    }

    /**
     * 综合联动详情页面弹窗接中转接口----预案列表
     */
    @RequestMapping("getPlanListByEventId")
    public void getPlanListByEventId(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        try {
            logger.info("------getPlanListByEventId-----start-------");
            String eventId = req.getParameter("eventId");
            String planReId = req.getParameter("planReId");
            if (StringUtil.isEmpty(eventId) && StringUtil.isEmpty(planReId)) {
                responseErrorData("json error", resp);
                return;
            }
            HttpClient httpClient = new DefaultHttpClient();
            //172.82.4.48:8080,部署173.82.57.45:8080
            String url = "http://173.82.57.45:8080/scooper-plan/api/plan/resp/getPlanListByEventId?eventId=" + eventId + "&token=eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6ImlvYyIsInVzZXJJZCI6MTAyNDEsIkludmFsaWRUaW1lIjoiU3VuIEF1ZyAxNiAxMTo1ODoxMCBDU1QgMjAyMCJ9.MhyP4xolXH5L4qHNhw_HNc8GIBwKQtgFZWwo5Wd6Jmc_10241";
            String url2 = "http://173.82.57.45:8080/scooper-plan/data/plan/reman/loadPlanRunData?planReId=" + planReId + "&token=eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6ImlvYyIsInVzZXJJZCI6MTAyNDEsIkludmFsaWRUaW1lIjoiU3VuIEF1ZyAxNiAxMTo1ODoxMCBDU1QgMjAyMCJ9.MhyP4xolXH5L4qHNhw_HNc8GIBwKQtgFZWwo5Wd6Jmc_10241";
            HttpGet httpGet = new HttpGet();
            if (!StringUtil.isEmpty(eventId)) {
                httpGet.setURI(URI.create(url));
            }
            if (!StringUtil.isEmpty(planReId)) {
                httpGet.setURI(URI.create(url2));
            }
            httpGet.setHeader("Content-type", "application/json;charset=utf-8");
            HttpResponse execute = httpClient.execute(httpGet);
            HttpEntity entity = execute.getEntity();
            resultObj.put("error_code", 0);
            resultObj.put("error_msg", "获取成功");
            resultObj.put("data", JSONObject.parseObject(EntityUtils.toString(entity)));
            responseData(resultObj.toString(), resp);

        } catch (Exception e) {
            resultObj.put("error_code", 0);
            resultObj.put("error_msg", "获取成功");
            responseData(resultObj.toString(), resp);
            e.printStackTrace();
        }

    }

    /**
     * 综合联动详情页面弹窗接中转接口----仓库列表
     */
    @RequestMapping("getWareHouseList")
    public void getWareHouseList(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        try {
            logger.info("------getWareHouseList-----start-------");
            String str = getRequestBodyString(req);
            if (StringUtil.isEmpty(str)) {
                responseErrorData("json error", resp);
                return;
            }
            JSONObject reqjson = JSONObject.parseObject(str);
//            String key = reqjson.getString("key");
            String wareHouseId = reqjson.getString("wareHouseId");
            HttpClient httpClient = new DefaultHttpClient();
            //172.82.4.50:9989,,,,,部署173.82.57.46:9999
           // String url3 = "http://173.82.57.46:9999/ecis-access/api/emerBaseData/getWareHouseList";
            String url3 = "http://173.82.57.47:9989/ecis-access/api/emerBaseData/getWareHouseList";
            //String url4 = "http://173.82.57.46:9999/ecis-access/api/emerBaseData/getSuppliesInfo";
            String url4 = "http://173.82.57.47:9989/ecis-access/api/emerBaseData/getSuppliesInfo";
            HttpPost httpPost = new HttpPost();
            httpPost.setHeader("Content-type", "application/json;charset=utf-8");
            httpPost.setHeader("token", "eyJhbGciOiJIUzI1NiJ9.eyJ1c2VyTmFtZSI6ImlvYyIsInVzZXJJZCI6MTAyNDEsIkludmFsaWRUaW1lIjoiU3VuIEF1ZyAxNiAxMTo1ODoxMCBDU1QgMjAyMCJ9.MhyP4xolXH5L4qHNhw_HNc8GIBwKQtgFZWwo5Wd6Jmc_10241");
            if (!StringUtil.isEmpty(wareHouseId)) {
                httpPost.setURI(URI.create(url4));
                StringEntity stringEntity = new StringEntity(JSONObject.toJSONString(reqjson), "utf-8");
                httpPost.setEntity(stringEntity);
            } else {
                httpPost.setURI(URI.create(url3));
                StringEntity stringEntity = new StringEntity(JSONObject.toJSONString(reqjson), "utf-8");
                stringEntity.setContentType("application/json");
                httpPost.setEntity(stringEntity);
            }
            httpPost.setHeader("Content-type", "application/json;charset=utf-8");
            HttpResponse execute = httpClient.execute(httpPost);
            HttpEntity entity = execute.getEntity();
            resultObj.put("error_code", 0);
            resultObj.put("error_msg", "获取成功");
            resultObj.put("data", JSONObject.parseObject(EntityUtils.toString(entity)));
            responseData(resultObj.toString(), resp);

        } catch (Exception e) {
            resultObj.put("error_code", 0);
            resultObj.put("error_msg", "获取成功");
            responseData(resultObj.toString(), resp);
            e.printStackTrace();
        }

    }

    /**
     * 综合联动   人员点位撒点
     */
    @RequestMapping("getPersonGisSearch")
    public void getPersonGisSearch(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        try {
            logger.info("------getWareHouseList-----start-------");
            String str = getRequestBodyString(req);
//            if (StringUtil.isEmpty(str)) {
//                responseErrorData("json error", resp);
//                return;
//            }
            JSONObject reqjson = JSONObject.parseObject(str);
            JSONObject jsonObject = new JSONObject();
            if (reqjson != null) {
                String eventId = reqjson.getString("eventId");
                String distance = reqjson.getString("distance");

                jsonObject.put("propKey", eventId);
                jsonObject.put("distance", distance);
            }
            HttpClient httpClient = new DefaultHttpClient();
            //172.82.4.50:9989,,,,,部署173.82.57.46:9999
           // String url3 = "http://173.82.57.46:9999/ecis-access/api/event/gisSearch?key=XJYJ_2020_XZJSC";
            String url3 = "http://173.82.57.47:9989/ecis-access/api/event/gisSearch?key=XJYJ_2020_XZJSC";
            HttpPost httpPost = new HttpPost();
            httpPost.setHeader("Content-type", "application/json;charset=utf-8");
            httpPost.setURI(URI.create(url3));
            StringEntity stringEntity = new StringEntity(jsonObject.toString(), "utf-8");
            stringEntity.setContentType("application/json");
            httpPost.setEntity(stringEntity);

            HttpResponse execute = httpClient.execute(httpPost);
            HttpEntity entity = execute.getEntity();

            JSONObject data = JSONArray.parseObject(JSONObject.parseObject(EntityUtils.toString(entity)).getString("data"));
            List<PersonGisSearch> list = JSONArray.parseArray(data.getString("list"), PersonGisSearch.class);
            List<PersonGisSearch> newList = new ArrayList<>();
            for (PersonGisSearch personGisSearch : list) {
                if (personGisSearch.getPosStatus().equals("offline") || personGisSearch.getPosStatus().equals("online")) {
                    newList.add(personGisSearch);
                }
            }
            newList.sort(new Comparator<PersonGisSearch>() {
                @Override
                public int compare(PersonGisSearch o1, PersonGisSearch o2) {
                    String name1 = o1.getName();
                    String name2 = o2.getName();
                    return name1.compareTo(name2);
                }
            });
////流处理必须要spring4.x以上版本 todo
//            List<PersonGisSearch> newList = list.stream().filter((person) -> person.getPosStatus().equals("online")||person.getPosStatus().equals("offline")).collect(Collectors.toList());
            resultObj.put("error_code", 0);
            resultObj.put("error_msg", "获取成功");
            resultObj.put("list", newList);
            responseData(resultObj.toString(), resp);

        } catch (Exception e) {
            resultObj.put("error_code", 0);
            resultObj.put("error_msg", "获取失败");
            responseData(resultObj.toString(), resp);
            e.printStackTrace();
        }

    }

    /**
     * 综合联动   人员电话查询-用于拨号
     */
    @RequestMapping("getPersonGisPhone")
    public void getPersonGisPhone(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        try {
            logger.info("------getWareHouseList-----start-------");
            String str = getRequestBodyString(req);
//            if (StringUtil.isEmpty(str)) {
//                responseErrorData("json error", resp);
//                return;
//            }
            JSONObject reqjson = JSONObject.parseObject(str);
            JSONObject jsonObject = new JSONObject();
            if (reqjson != null) {
                String memId = reqjson.getString("memId");
                jsonObject.put("memId", memId);
                jsonObject.put("key", "XJYJ_2020_XZJSC");
            }
            HttpClient httpClient = new DefaultHttpClient();
            //172.82.4.50:9989,,,,,部署173.82.57.46:9999
            //String url3 = "http://173.82.57.46:9999/ecis-access/api/login/getMemInfo";
            String url3 = "http://173.82.57.47:9989/ecis-access/api/login/getMemInfo";
            HttpPost httpPost = new HttpPost();
            httpPost.setHeader("Content-type", "application/json;charset=utf-8");
            httpPost.setURI(URI.create(url3));
            StringEntity stringEntity = new StringEntity(jsonObject.toString(), "utf-8");
            stringEntity.setContentType("application/json");
            httpPost.setEntity(stringEntity);

            HttpResponse execute = httpClient.execute(httpPost);
            HttpEntity entity = execute.getEntity();
            resultObj.put("error_code", 0);
            resultObj.put("error_msg", "获取成功");
            resultObj.put("data", JSONObject.parseObject(EntityUtils.toString(entity)));
            responseData(resultObj.toString(), resp);

        } catch (Exception e) {
            resultObj.put("error_code", 0);
            resultObj.put("error_msg", "获取成功");
            responseData(resultObj.toString(), resp);
            e.printStackTrace();
        }

    }

    /**
     * 少数民族-人口统计分析
     */
    @RequestMapping("getMinorityAnalysis")
    public void getMinorityAnalysis(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();

        //户籍人口
        int HuJi = personDataService.getHuJi("户籍人口");
        //来沪人口
        int LaiHu = personDataService.getHuJi("来沪人口");
        //男性
        int man = personDataService.getHuJi("男性");
        //女性
        int woman = personDataService.getHuJi("女性");
        //少数民族总人口
        int total = personDataService.getHuJi("少数民族人口");
        //14岁以下儿童
        int children = personDataService.getHuJi("14岁以下的儿童");
        //14岁以上儿童占比
        double childrenPercent = Double.valueOf(children) / total;
        //60岁以上老人
        double old = personDataService.getHuJi("60岁以上老年人");
        //60岁以上老人占比
        double oldPercent = Double.valueOf(old) / total;
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("HuJi", HuJi);
        resultObj.put("LaiHu", LaiHu);
        resultObj.put("man", man);
        resultObj.put("woman", woman);
        resultObj.put("children", children);
        resultObj.put("childrenPercent", childrenPercent);
        resultObj.put("old", old);
        resultObj.put("oldPercent", oldPercent);
        resultObj.put("total", total);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 少数民族-人口街道分布
     */
    @RequestMapping("getMinorityByStreet")
    public void getMinorityByStreet(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();

        //户籍人口
        List<AppDsjzxQqssrk> street = personDataService.getMinorityByStreet();
        int total = personDataService.getHuJi("少数民族人口");
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("street", street);
        resultObj.put("total", total);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 少数民族-人口年龄统计
     */
    @RequestMapping("getMinorityByAge")
    public void getMinorityByAge(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();

        //户籍人口
        Map hj = personDataService.getSegmentByAge();
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("hj", hj);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 少数民族-人员点位撒点
     */
    private static Map<String, List> cache = new ConcurrentHashMap();

    @RequestMapping("getMinorityByAddress")
    public void getMinorityByAddress(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        //户籍人口
        if (cache.size() == 0) {
            List<HpBasSyrkJzdz> lngLat = personDataService.geLngLat();
            cache.put("lngLat", lngLat);
            resultObj.put("lngLat", lngLat);
        } else {
            resultObj.put("lngLat", cache);
        }
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);
    }


    @Resource
    private SanitationService sanitationService;
    @Resource
    private XuJianApiService xuJianApiService;

    /**
     * 风险点库数据查询 废弃不用
     */
    @RequestMapping("getFxdkList")
    public void getFxdkList(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);
        String eventid = jsonObject.getString("eventid");
        //原图层事件
        XJEvent xjEvent = xuJianApiService.getXjEventByEventId(eventid);
        String[] mag = xjEvent.getEvent_gis().split(",");
        //新图层
        List<SanitationInfo> FxdkList = crowdSituationApiService.getFxdkList();
        GlobalCoordinates source = new GlobalCoordinates(Double.parseDouble(mag[1]), Double.parseDouble(mag[0]));

        GlobalCoordinates target = null;
        for (SanitationInfo sanitationInfo : FxdkList) {
            if (StringUtil.isNotEmpty(sanitationInfo.getLat())) {
                target = new GlobalCoordinates(Double.parseDouble(sanitationInfo.getLat()), Double.parseDouble(sanitationInfo.getLng()));
                double meter = CaculateDistanceTest.getDistanceMeter(source, target, Ellipsoid.WGS84);
                sanitationInfo.setMeter(meter);
            }
        }
        resultObj.put("data", FxdkList);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);
    }

    /***
     * 户籍人口数
     */
    @RequestMapping("getHuJiCount")
    public void getHuJiCount(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();

        //户籍人口
        HpPersonHouseStatistics hj = crowdSituationApiService.getHuJiCount();
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("hj", hj.getSz());
        responseData(resultObj.toString(), resp);
    }

    /**
     * 根据居委点位计算半径一公里，两公里的距离 todo
     */
    @RequestMapping("getJuWeiDistance")
    public void getJuWeiDistance(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);
        String lng = jsonObject.getString("lng");
        String lat = jsonObject.getString("lat");
        String distance = jsonObject.getString("distance");
        //距离
        List<JuWeiPopulation> JuWeiList = laoXiMenApiService.getJuWeiList();
        GlobalCoordinates source = new GlobalCoordinates(Double.parseDouble(lat), Double.parseDouble(lng));
        List<JuWeiPopulation> list = new ArrayList<>();
        GlobalCoordinates target;
        for (JuWeiPopulation juWeiPopulation : JuWeiList) {
            if (StringUtil.isNotEmpty(juWeiPopulation.getPoint_x())) {
                target = new GlobalCoordinates(Double.parseDouble(juWeiPopulation.getPoint_y()), Double.parseDouble(juWeiPopulation.getPoint_x()));
                double meter = CaculateDistanceTest.getDistanceMeter(source, target, Ellipsoid.WGS84);
                if (meter < Double.valueOf(distance)) {
                    juWeiPopulation.setMeter(meter);
                    list.add(juWeiPopulation);
                }
            }
        }
        if (list.size() == 0) {
            for (JuWeiPopulation juWeiPopulation : JuWeiList) {
                if (StringUtil.isNotEmpty(juWeiPopulation.getPoint_x())) {
                    target = new GlobalCoordinates(Double.parseDouble(juWeiPopulation.getPoint_y()), Double.parseDouble(juWeiPopulation.getPoint_x()));
                    double meter = CaculateDistanceTest.getDistanceMeter(source, target, Ellipsoid.WGS84);
                    juWeiPopulation.setMeter(meter);
                    list.add(juWeiPopulation);
                }
            }
            Collections.sort(list, new Comparator<JuWeiPopulation>() {
                @Override
                public int compare(JuWeiPopulation o1, JuWeiPopulation o2) {
                    double v = o1.getMeter() - o2.getMeter();
                    if (v > 0) {
                        return 0;
                    } else {
                        return -1;
                    }

                }
            });
            resultObj.put("data", list.get(0));
        } else {
            resultObj.put("data", list);
        }

        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);
    }

    @Resource
    private SynthesisService synthesisService;

    /**
     * 全区特殊服务救助站详情
     */
    @RequestMapping("getSpecialPersonnelListByStatus")
    public void getSpecialPersonnelListByStatus(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);
        String status = jsonObject.getString("status");
        List<HpSynthesisJudicature> hpSynthesisJudicatureList = synthesisService.getSpecialPersonnelList(status);
        resultObj.put("data", hpSynthesisJudicatureList);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);
    }

    /**
     * 全区特殊服务人群详情
     */
    @RequestMapping("getHpPersonCntsListByStatus")
    public void getHpPersonCntsListByStatus(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);
        Map map = new ConcurrentHashMap();
        String status = jsonObject.getString("status");

        List<HpPersonCnts> hp = synthesisService.getHpPersonCntsListByStatus(status);
        for (HpPersonCnts h : hp) {
            map.put(h.getAdress(), h.getSum());
        }
        resultObj.put("data", map);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);
    }

    /**
     * 全区特殊人员总数
     */
    @RequestMapping("getSpecialPersonnelCount")
    public void getSpecialPersonnelCount(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        List list = new ArrayList();
        List<HpSynthesisJudicature> hp = synthesisService.getSpecialPersonnelCount();
        for (HpSynthesisJudicature h : hp) {
            if (h.getStatus().equals("s")) {
                h.setName("司法援助站");
            }
            if (h.getStatus().equals("q")) {
                h.setName("青少年社工站");
            }
            if (h.getStatus().equals("j")) {
                h.setName("矫正社工站");
            }
            if (h.getStatus().equals("d")) {
                h.setName("禁毒社工站");
            }
        }
        list.addAll(hp);
        HpPersonCnts hpPersonCnts = new HpPersonCnts();
        List<HpPersonCnts> hpPersonCntsList = new ArrayList();
        String[] strings = {"x", "f", "j", "d", "t"};
        for (int i = 0; i < strings.length; i++) {
            hpPersonCnts = synthesisService.getHpPersonCntsCount(strings[i]);
            hpPersonCntsList.add(hpPersonCnts);
        }
        for (HpPersonCnts p : hpPersonCntsList) {
            converter(p);
        }
        list.addAll(hpPersonCntsList);
        resultObj.put("data", list);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);
    }

    /**
     * 根据状态值获取全区特殊人员年度变动趋势详情
     */
    @RequestMapping("getChangeTrendInfoByStatus")
    @ResponseBody
    public Object getChangeTrendInByStatus(@RequestBody HpPersonCnts hpPersonCnts ){
        List<HpPersonCnts> hpPersonCntsList = synthesisService.getSpecialPersonList(hpPersonCnts);
        Map<String, List<HpPersonCnts>> groupMap = new HashMap<>();
        //根据街道分组 <街道名， List>
        listGroupByAdress(hpPersonCntsList,groupMap);
        List<HpPersonCnts> finalList = new ArrayList<>();
        Map<String,String> finalMap = new HashMap<>();
        for(Map.Entry<String,List<HpPersonCnts>> map : groupMap.entrySet()){
            List<HpPersonCnts> list = map.getValue();
            //根据月做排序
            Collections.sort(list, new Comparator<HpPersonCnts>() {
                public int compare(HpPersonCnts o1, HpPersonCnts o2) {
                    // TODO Auto-generated method stub
                    return Integer.valueOf(o2.getTimes().substring(5,7)) -  Integer.valueOf(o1.getTimes().substring(5,7));//降序
                }
            });
            finalMap.put(list.get(0).getAdress(),list.get(0).getNumber_cnts());
        }
        JSONObject resultObj = new JSONObject();
        resultObj.put("data", finalMap);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        return resultObj;
    }

    /**
     * 根据状态做分组
     * @param hpPersonCntsList
     * @param groupMap
     */
    private void listGroupByAdress(List<HpPersonCnts> hpPersonCntsList, Map<String, List<HpPersonCnts>> groupMap){
        String key;
        List<HpPersonCnts> listTemp;
        for(HpPersonCnts personCnts : hpPersonCntsList){
            key = personCnts.getAdress();
            listTemp = groupMap.get(key);
            if(null == listTemp){
                listTemp = new ArrayList<HpPersonCnts>();
                groupMap.put(key, listTemp);
            }
            listTemp.add(personCnts);
        }
    }

    /**
     * 根据状态值获取全区特殊人员年度变动趋势详情
     */
    @RequestMapping("getChangeTrendInfoByStatusOld")
    public void getChangeTrendInfoByStatus(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);
        String year = jsonObject.getString("year");
        String status = jsonObject.getString("status");
        Map maps = new ConcurrentHashMap();
        List<HpPersonCnts> hpPersonCntsList = synthesisService.getChangeTrendInfoByStatus(year, status);
        for (HpPersonCnts h : hpPersonCntsList) {
            maps.put(h.getAdress(), h.getSum());
        }
        resultObj.put("data", maps);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);
    }

    /**
     * 综合联动-预案字典
     */
    @RequestMapping("getPlanType")
    public void getPlanType(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);
        String type = jsonObject.getString("type");

        List<HpMenu> types = crowdSituationApiService.getPlanType(type);
        resultObj.put("data", types);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);
    }

    /**
     * 综合联动-33预案
     */
    @RequestMapping("getContingencyPlan")
    public void getContingencyPlan(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
//两个参数，预案大类，预案名称
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);
        String type = jsonObject.getString("type");
        String title = jsonObject.getString("title");
        String level = jsonObject.getString("level");

        List<HpMenu> street = crowdSituationApiService.getContingencyPlan(type, title, level);
        for (HpMenu hpMenu : street) {
            if (hpMenu != null && hpMenu.getDetail() != null) {
                String replace = hpMenu.getDetail().replace("/", "<br/><img/>");
                String replace1 = replace.replace("\n", "");
                hpMenu.setDetail(replace1);
            }
        }
        String name = crowdSituationApiService.getTitle(title);
        List<HpMenu> menuTree = buildMenuTree(street, "root", name);

        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("menuTree", menuTree);
        resultObj.put("name", name);
        responseData(resultObj.toString(), resp);
    }

    public List<HpMenu> buildMenuTree(List<HpMenu> menuList, String pid, String name) {
        List<HpMenu> treeList = new ArrayList<>();
        for (HpMenu menu : menuList) {
            if (StringUtils.equals(pid, menu.getParent_id())) {
                menu.setChildMenus(buildMenuTree(menuList, menu.getId(), name));
                menu.setName(name);
                treeList.add(menu);
            }
        }
        return treeList;
    }

    /**
     * 全区特殊人员年度变动趋势--最新
     */
    @RequestMapping("getChangeTrendInfo")
    @ResponseBody
    public Object getSpecialPersonInfoOnYear(){
        HpPersonCnts hpPersonCnts = new HpPersonCnts();
        List<HpPersonCnts> hpPersonCntsList = synthesisService.getSpecialPersonList(hpPersonCnts);
        //根据状态做分组
        Map<String, List<HpPersonCnts>> groupMap = new HashMap<>();
        listGroupByStatus(hpPersonCntsList ,groupMap);
        // 对分组之后的 value按times参数做统计
        //<status,List>
        List<HpPersonCnts> finalList = new ArrayList<>();
        for(Map.Entry<String,List<HpPersonCnts>> map : groupMap.entrySet()){
            List<HpPersonCnts> list = map.getValue();
            //根据times做统计 times: yyyy-mm
            // 先分组 <Times, List>
            Map<String, List<HpPersonCnts>> subGroupMap = new HashMap<>();
            listGroupByTimes(list ,subGroupMap);
            List<HpPersonCnts> hpPersonCntsListFinalList = new ArrayList<>();
            //求和
            for(Map.Entry<String, List<HpPersonCnts>> timeMap : subGroupMap.entrySet()){
                String timesKey = timeMap.getKey();
                List<HpPersonCnts> hpPersonCntsList1 = timeMap.getValue();
                Integer sum = 0;
                for(HpPersonCnts hpPersonCnts1 : hpPersonCntsList1){
                    sum += Integer.valueOf(hpPersonCnts1.getNumber_cnts());
                }
                //按月累加后的HpPersonCnts
                HpPersonCnts hpPersonCntsFinal = new HpPersonCnts();
                if(hpPersonCntsList1.size() > 0){
                    hpPersonCntsFinal.setSum(Integer.toString(sum));
                    hpPersonCntsFinal.setTimes(timesKey.substring(0,4));
                    hpPersonCntsFinal.setStatus(hpPersonCntsList1.get(0).getStatus());
                    hpPersonCntsFinal.setYearMonth(timesKey);
                    converter(hpPersonCntsFinal);
                }
                hpPersonCntsListFinalList.add(hpPersonCntsFinal);
            }
            //对hpPersonCntsListFinalList 按年做分组， 并按年月做排序 ，取出每年最新的日期的数据
            Map<String, List<HpPersonCnts>> yearHpPersonCntsListMap = new HashMap<>();
            listGroupByTimesYear(hpPersonCntsListFinalList,yearHpPersonCntsListMap);
            for(Map.Entry<String,List<HpPersonCnts>> yearMap: yearHpPersonCntsListMap.entrySet()){
                List<HpPersonCnts> hpPersonCntsListTemp = yearMap.getValue();
                //对集合按月做排序(降序)，
                sortByMonthDesc(hpPersonCntsListTemp);
                //取每年最大月份
                finalList.add(hpPersonCntsListTemp.get(0));
            }
        }
        JSONObject resultObj = new JSONObject();
        resultObj.put("data", finalList);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        return resultObj;
    }

    /**
     * 根据月份做排序
     * @param hpPersonCntsListTemp
     */
    private void sortByMonthDesc(List<HpPersonCnts> hpPersonCntsListTemp){
        Collections.sort(hpPersonCntsListTemp, new Comparator<HpPersonCnts>() {
            public int compare(HpPersonCnts o1, HpPersonCnts o2) {
                // TODO Auto-generated method stub
                return Integer.valueOf(o2.getYearMonth().substring(5,7)) -  Integer.valueOf(o1.getYearMonth().substring(5,7));//降序
            }
        });
    }

    /**
     * 根据状态做分组
     * @param hpPersonCntsList
     * @param groupMap
     */
    private void listGroupByStatus(List<HpPersonCnts> hpPersonCntsList, Map<String, List<HpPersonCnts>> groupMap){
        String key;
        List<HpPersonCnts> listTemp;
        for(HpPersonCnts personCnts : hpPersonCntsList){
            key = personCnts.getStatus();
            listTemp = groupMap.get(key);
            if(null == listTemp){
                listTemp = new ArrayList<HpPersonCnts>();
                groupMap.put(key, listTemp);
            }
            listTemp.add(personCnts);
        }
    }

    /**
     * 根据日期做分组
     * @param hpPersonCntsList
     * @param groupMap
     */
    private void listGroupByTimes(List<HpPersonCnts> hpPersonCntsList, Map<String, List<HpPersonCnts>> groupMap){
        String key;
        List<HpPersonCnts> listTemp;
        for(HpPersonCnts personCnts : hpPersonCntsList){
            key = personCnts.getTimes();
            listTemp = groupMap.get(key);
            if(null == listTemp){
                listTemp = new ArrayList<HpPersonCnts>();
                groupMap.put(key, listTemp);
            }
            listTemp.add(personCnts);
        }
    }

    /**
     * 根据日期中年做分组
     * @param hpPersonCntsList
     * @param groupMap
     */
    private void listGroupByTimesYear(List<HpPersonCnts> hpPersonCntsList, Map<String, List<HpPersonCnts>> groupMap){
        String key;
        List<HpPersonCnts> listTemp;
        for(HpPersonCnts personCnts : hpPersonCntsList){
            key = personCnts.getTimes();
            listTemp = groupMap.get(key);
            if(null == listTemp){
                listTemp = new ArrayList<HpPersonCnts>();
                groupMap.put(key, listTemp);
            }
            listTemp.add(personCnts);
        }
    }

    /**
     * 全区特殊人员年度变动趋势 (作废--加了Old)
     */
    @RequestMapping("getChangeTrendInfoOld")
    public void getChangeTrendInfo(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        List<HpPersonCnts> hpPersonCnts = synthesisService.getChangeTrendInfo();
        for (HpPersonCnts hp : hpPersonCnts) {
            converter(hp);
        }
        resultObj.put("data", hpPersonCnts);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);
    }

    public void converter(HpPersonCnts hp) {
        if (hp.getStatus().equals("x")) {
            hp.setName("刑满释放者");
//            map.put("刑满释放者", hp.getSum());
        }
        else if (hp.getStatus().equals("f")) {
            hp.setName("服务对象");
        }
        else if (hp.getStatus().equals("j")) {
            hp.setName("精神障碍者");
        }
        else if (hp.getStatus().equals("d")) {
            hp.setName("矫正对象");
        }
        else if (hp.getStatus().equals("t")) {
            hp.setName("吸毒人员");
        }
    }

    /**
     * 全区特殊人员月度变动趋势（）刑满释放，精神障碍，矫正对象
     */
    @RequestMapping("getChangeTrendMonthByStatus")
    public void getChangeTrendMonthByStatus(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);
        String year = jsonObject.getString("year");
        String[] strings = {"x", "j", "d"};
        List<HpPersonCnts> hpPersonCnts = new ArrayList<>();
        Map map = new HashMap();
        for (int i = 0; i < strings.length; i++) {
            hpPersonCnts = synthesisService.getChangeTrendMonthByStatus(strings[i], year);
            if (strings[i].equals("x")) {
                map.put("x", hpPersonCnts);
            }
            if (strings[i].equals("j")) {
                map.put("j", hpPersonCnts);
            }
            if (strings[i].equals("d")) {
                map.put("d", hpPersonCnts);
            }
        }
        resultObj.put("data", map);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);
    }

    /**
     * 获取南京东路的单位信息
     */
    @RequestMapping("getNdUnitByType")
    public void getNdUnitByType(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);
        String type = jsonObject.getString("type");
        List<NdUnit> ndUnitList = nanDongApiService.getNdUnitByType(type);
        resultObj.put("data", ndUnitList);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);
    }

    /**
     * 人群态势lbs接公安分局数据
     */
    @RequestMapping("getLbsPoliceData")
    public void getLbsPoliceData(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
//        String [] strings=Constants.LBS.split(",");
        List<HpRealLbs> hpRealLbsList = null;
//        for (int i = 0; i < strings.length; i++) {
        hpRealLbsList = gaApiService.getLbsPoliceData();

//        }
        resultObj.put("data", hpRealLbsList);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);
    }

    /**
     * 黄浦区景区客流历史数据查询
     */
    @RequestMapping("getHistorySpotDataCount")
    public void getHistorySpotDataCount(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);
        //景区名称
        String spotName = jsonObject.getString("spotName");
        //查询条件
        String day = jsonObject.getString("day");
        //每小时
        List<SysRefinedCrowdSituation> everyHour = crowdSituationApiService.getHistorySpotDataCount(spotName, day);

        //实时
        List<SysRefinedCrowdSituation> realTime = crowdSituationApiService.getRealTimeCount(spotName, day);

        SysRefinedCrowdSituation sc = crowdSituationApiService.getMaxNumber(day, day, spotName);
        SysRefinedCrowdSituation total = crowdSituationApiService.getTotalNumber(day, day, spotName);
        Integer njdl = crowdSituationApiService.getNjdlTotalNumber();
        Integer njdlHistory = crowdSituationApiService.getNjdlHistoryTotalNumber(day);


//        ExcelUtil<SysRefinedCrowdSituation> util = new ExcelUtil<SysRefinedCrowdSituation>(SysRefinedCrowdSituation.class);
        //asm对spring3.x不兼容，问题待解决
//        util.exportExcel(crowdSituations,"历史景区客流数据");
        String sequential = null;
        if (total != null && total.getSpotName() != null) {
            if ("南京路".equals(total.getSpotName())) {
                if (day.equals(DateUtils.getDate())) {
                    total.setTotalNumber(njdl);
                } else {
                    total.setTotalNumber(njdlHistory);
                }

            }
        }
        if (day.equals(DateUtils.getDate())) {
            if ("南京路".equals(spotName)) {
                sequential = crowdSituationApiService.getNanJingHuanBiNow();
            }
            if ("豫园（内圈）".equals(spotName)) {
                sequential = hiveZdk57ApiService.getMonthOnMonthYYGFBySpotId();
            }
            if ("豫园（外圈）".equals(spotName)) {
                sequential = hiveZdk57ApiService.getMonthOnMonthBySpotId("YUYUAN");
            }
            if ("外滩".equals(spotName)) {
                sequential = hiveZdk57ApiService.getMonthOnMonthBySpotId("WAITAN");
            }
            if ("新天地".equals(spotName)) {
                sequential = hiveZdk57ApiService.getMonthOnMonthBySpotId("XINTIANDI");
            }
            if ("田子坊".equals(spotName)) {
                sequential = hiveZdk57ApiService.getMonthOnMonthBySpotId("TIANZIFANG");
            }
        } else {
            if ("南京路".equals(spotName)) {
                sequential = crowdSituationApiService.getNanJingHuanBi(day);
            }
            if ("豫园（内圈）".equals(spotName)) {
                sequential = hiveZdk57ApiService.getMonthOnMonthYYGFBySpotIdDay(day);
            }
            if ("豫园（外圈）".equals(spotName)) {
                sequential = hiveZdk57ApiService.getMonthOnMonthBySpotIdDay("YUYUAN", day);
            }
            if ("外滩".equals(spotName)) {
                sequential = hiveZdk57ApiService.getMonthOnMonthBySpotIdDay("WAITAN", day);
            }
            if ("新天地".equals(spotName)) {
                sequential = hiveZdk57ApiService.getMonthOnMonthBySpotIdDay("XINTIANDI", day);
            }
            if ("田子坊".equals(spotName)) {
                sequential = hiveZdk57ApiService.getMonthOnMonthBySpotIdDay("TIANZIFANG", day);
            }
        }
        if (sequential == null) {
            sequential = "0";
        }
        if (total != null && total.getTotalNumber() != null) {
            resultObj.put("total", total.getTotalNumber());
        } else {
            resultObj.put("total", 0);
        }
        resultObj.put("everyHour", everyHour);
        resultObj.put("huanbi", sequential);
        resultObj.put("realTime", realTime);

        resultObj.put("maxTime", sc.getRealtimeNumber() + "(" + sc.getCreateTime().substring(11, 16) + ")");
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);
    }

    /**
     * 黄浦区景区客流历史数据全部
     */
    @RequestMapping("getHistorySpotDataAllCount")
    public void getHistorySpotDataAllCount(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);
        //景区名称
        String spotName = jsonObject.getString("spotName");
        //查询条件
        String day = jsonObject.getString("day");
        //每小时
        List<SysRefinedCrowdSituation> everyHour = crowdSituationApiService.getHistorySpotDataAllCount(spotName, day);

        //实时
        List<SysRefinedCrowdSituation> realTime = crowdSituationApiService.getRealTimeAllCount(spotName, day);
        String[] spotcodeArr = Constants.SPOTCODELIST.split(",");
        SysRefinedCrowdSituation sc = null;
        SysRefinedCrowdSituation total = null;
        Map<String, String> max = new HashMap<>();
        Map<String, Integer> all = new HashMap<>();
        Integer njdl = crowdSituationApiService.getNjdlTotalNumber();
        Integer njdlHistory = crowdSituationApiService.getNjdlHistoryTotalNumber(day);
//        ExcelUtil<SysRefinedCrowdSituation> util = new ExcelUtil<SysRefinedCrowdSituation>(SysRefinedCrowdSituation.class);
        //asm对spring3.x不兼容，问题待解决
//        util.exportExcel(crowdSituations,"历史景区客流数据");

        Map map = new HashMap();
        for (int i = 0; i < spotcodeArr.length; i++) {
            sc = crowdSituationApiService.getMaxAllNumber(day, day, spotcodeArr[i]);
            if (sc != null && sc.getSpotName() != null && sc.getRealtimeNumber() != null && sc.getCreateTime() != null) {
                max.put(sc.getSpotName(), sc.getRealtimeNumber() + "(" + sc.getCreateTime().substring(11, 16) + ")");
            }
            total = crowdSituationApiService.getTotalAllNumber(day, day, spotcodeArr[i]);
            if (total != null && total.getSpotName() != null) {
                if ("南京路".equals(total.getSpotName())) {
                    if (day.equals(DateUtils.getDate())) {
                        total.setTotalNumber(njdl);
                    } else {
                        total.setTotalNumber(njdlHistory);
                    }

                }

                all.put(total.getSpotName(), total.getTotalNumber());
            }
        }
        String nanJingHuanBi = crowdSituationApiService.getNanJingHuanBi(day);
        if (nanJingHuanBi != null) {
            map.put("南京路", nanJingHuanBi);
        } else {
           String temp =  crowdSituationApiService.getNanJingHuanBiNow();
            map.put("南京路", crowdSituationApiService.getNanJingHuanBiNow());
        }
        String yuyuan_nei = hiveZdk57ApiService.getMonthOnMonthYYGFBySpotIdDay(day);
        if (yuyuan_nei != null) {
            map.put("豫园（内圈）", yuyuan_nei);
        } else {
            map.put("豫园（内圈）", hiveZdk57ApiService.getMonthOnMonthYYGFBySpotId());
        }

        String yuyuan_wai = hiveZdk57ApiService.getMonthOnMonthBySpotIdDay("YUYUAN", day);
        if (yuyuan_wai != null) {
            map.put("豫园（外圈）", yuyuan_wai);
        } else {
            map.put("豫园（外圈）", hiveZdk57ApiService.getMonthOnMonthBySpotId("YUYUAN"));
        }
        String waitan = hiveZdk57ApiService.getMonthOnMonthBySpotIdDay("WAITAN", day);
        if (waitan != null) {
            map.put("外滩", waitan);
        } else {
            map.put("外滩", hiveZdk57ApiService.getMonthOnMonthBySpotId("WAITAN"));
        }

        String xintiandi = hiveZdk57ApiService.getMonthOnMonthBySpotIdDay("XINTIANDI", day);
        if (xintiandi != null) {
            map.put("新天地", xintiandi);
        } else {
            map.put("新天地", hiveZdk57ApiService.getMonthOnMonthBySpotId("XINTIANDI"));
        }

        String tianzifang = hiveZdk57ApiService.getMonthOnMonthBySpotIdDay("TIANZIFANG", day);
        if (tianzifang != null) {
            map.put("田子坊", tianzifang);
        } else {
            map.put("田子坊", hiveZdk57ApiService.getMonthOnMonthBySpotId("TIANZIFANG"));
        }


        resultObj.put("everyHour", everyHour);
        resultObj.put("huanbi", map);
        resultObj.put("realTime", realTime);
        resultObj.put("total", all);
        resultObj.put("maxTime", max);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);
    }

    /**
     * 第三方接口历史客流数据查询  最新版 todo
     */
    @RequestMapping("getHistoryDataThree")
    public void getHistoryDataThree(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);
        String type = jsonObject.getString("type");
        List<NdPersonInfo> ndPersonInfoList = nanDongApiService.getPersonInfoByType(type);
        resultObj.put("data", ndPersonInfoList);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);
    }

    /**
     * 获取南京东路的人员信息
     */
    @RequestMapping("getPersonInfoByType")
    public void getPersonInfoByType(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);
        String type = jsonObject.getString("type");
        List<NdPersonInfo> ndPersonInfoList = nanDongApiService.getPersonInfoByType(type);
        resultObj.put("data", ndPersonInfoList);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);
    }

    /**
     * 南京路撒点
     */
    @RequestMapping("getNanDongPoint")
    public void getNanDongPoint(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);
        String type = jsonObject.getString("type");
        List<NanDongAiPoint> nanDongAiPointList = nanDongApiService.getNanDongPoint(type);
        for (NanDongAiPoint nd : nanDongAiPointList) {
            double[] map = MapUtil.bd09towgs84(Double.parseDouble(nd.getLng()), Double.parseDouble(nd.getLat()));
            nd.setLng(map[0] + "");
            nd.setLat(map[1] + "");
        }
        resultObj.put("data", nanDongAiPointList);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);
    }

    /**
     * 南京路各居委第四季度分数
     */
    @RequestMapping("getNanDongCommittee")
    public void getNanDongCommittee(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);
        String committee = jsonObject.getString("committee");
        List<NanDongCommitteeScore> committeeScoreList = nanDongApiService.getNanDongCommittee(committee);
        resultObj.put("data", committeeScoreList);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);
    }

    /**
     * 南京路各数据集合
     */
    @RequestMapping("getNanDongDataList")
    public void getNanDongDataList(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        //倒粪口
        List<NanDongDfKou> nanDongDataList = nanDongApiService.getNanDongDataList();
        //建档服务站
        List<NanDongDjService> nanDongDjServiceList = nanDongApiService.getNanDongDjServiceList();
        for (NanDongDjService nd : nanDongDjServiceList) {
            double[] map = MapUtil.bd09towgs84(Double.parseDouble(nd.getLng()), Double.parseDouble(nd.getLat()));
            nd.setLng(map[0] + "");
            nd.setLat(map[1] + "");
        }
        //历史保护建筑
        List<NanDongHistoryArchitecture> HistoryArchitectureList = nanDongApiService.getNanDongNanDongHistoryArchitectureList();
        //居住房
        List<NanDongJzHouse> jzHouseList = nanDongApiService.getNanDongJzHouseList();
        //垃圾厢房
        List<NanDongLiHouse> nanDongLiHouseList = nanDongApiService.getNanDongLiHouseList();

        //勤务点
        List<NanDongLwPoint> lwPointList = nanDongApiService.getNanDongLwPointList();
        for (NanDongLwPoint nd : lwPointList) {
            double[] map = MapUtil.bd09towgs84(Double.parseDouble(nd.getLng()), Double.parseDouble(nd.getLat()));
            nd.setLng(map[0] + "");
            nd.setLat(map[1] + "");
        }
        //不可移动文物
        List<NanDongNotMoveRelic> nanDongNotMoveRelicList = nanDongApiService.getNanDongNotMoveRelicList();
        //摊亭棚
        List<NanDongTtpInfo> ttpInfoList = nanDongApiService.getNanDongTtpInfoList();
        //单位厢房
        List<NanDongUnitHouse> unitHouseList = nanDongApiService.getNanDongUnitHouseList();

        resultObj.put("nanDongDataList", nanDongDataList);
        resultObj.put("NanDongDjService", nanDongDjServiceList);
        resultObj.put("HistoryArchitectureList", HistoryArchitectureList);
        resultObj.put("jzHouseList", jzHouseList);
        resultObj.put("nanDongLiHouseList", nanDongLiHouseList);
        resultObj.put("lwPointList", lwPointList);
        resultObj.put("nanDongNotMoveRelicList", nanDongNotMoveRelicList);
        resultObj.put("ttpInfoList", ttpInfoList);
        resultObj.put("unitHouseList", unitHouseList);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);
    }

    /**
     * 南京东路案件类型
     */
    @RequestMapping("getAjByType")
    public void getAjByType(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        List<NanDongAjType> nanDongAjTypes = nanDongApiService.getAjByType();
        List<NanDongAjType> count = nanDongApiService.getCountByType();
        int sum = nanDongApiService.getSum();

        List<NanDongAjType> Info = new ArrayList<>();
        List<NanDongAjType> allInfo = new ArrayList<>();
        for (NanDongAjType ajType : nanDongAjTypes) {
            Info = nanDongApiService.getAjInfo(ajType.getAj_type());
            allInfo.addAll(Info);
        }
        for (NanDongAjType nanDongAjType : count) {
            List list = new ArrayList();
            for (NanDongAjType dongAjType : allInfo) {
                if (dongAjType.getAj_type().equals(nanDongAjType.getAj_type())) {
                    list.add(dongAjType);
                    nanDongAjType.setInfoMap(list);
                }
            }
            Double percent = Double.valueOf(Double.valueOf(nanDongAjType.getNumber()) / Double.valueOf(sum));
            nanDongAjType.setPercent(percent);

        }

        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("nanDongAjTypes", nanDongAjTypes);
        resultObj.put("data", count);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 各类人员交互弹窗   老西门街道
     */
    @RequestMapping("getUserByIdentity")
    public void getUserByIdentity(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);
        String identity = jsonObject.getString("identity");
        int page = jsonObject.getInteger("page");
        List<AppIdentityModel> identityModelList = hiveZdk57ApiService.getUserByIdentity(identity, page, Constants.PAGESIZE);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", identityModelList);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 实有人口-户籍人口-变化趋势
     */
    @RequestMapping("getPopuDistribution")
    public void getPopuDistribution(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        //实有人口
        HpPersonHouseStatistics hp = crowdSituationApiService.getPopuDistribution();
        //户籍人口
        HpPersonHouseStatistics hj = crowdSituationApiService.getHuJiCount();
        //趋势
        List<HpPersonHouseStatistics> syrk = crowdSituationApiService.getEveryYear();
        List<HpPersonHouseStatistics> hjrk = crowdSituationApiService.getEveryYearHjRk();
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("hp", hp);
        resultObj.put("hj", hj);
        resultObj.put("syrk", syrk);
        resultObj.put("hjrk", hjrk);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 户籍人口按照街道分，户在人不在-人在户不在-人在户在-去向不明
     */
    @RequestMapping("getPopuDistributionByStreet")
    public void getPopuDistributionByStreet(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        //户籍人口
        List<HpPersonHouseStatistics> hj = crowdSituationApiService.getPopuDistributionByStreet();
        List<HpPersonHouseStatistics> count = crowdSituationApiService.getCountByType();
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("hj", hj);
        resultObj.put("count", count);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 人房关联-月份字典查询
     */
    @RequestMapping("getPopuHourseByMonth")
    public void getPopuHourseByMonth(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        Integer month = crowdSituationApiService.getPopuHourseByMonth();
        Integer year = crowdSituationApiService.getPopuHourseByYear();

        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("month", month);
        resultObj.put("year", year);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 人房关联-分离
     */
    @RequestMapping("getPopuHourse")
    public void getPopuHourse(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);
        String year = jsonObject.getString("year");
        List<HpPersonHouseStatistics> fenLi = crowdSituationApiService.getPopuHourse(year);
        List<HpPersonHouseStatistics> noFenLi = crowdSituationApiService.getPopuHourseNoFen(year);
        List<HpPersonHouseStatistics> trendH = crowdSituationApiService.geteveryYearTrend();
        List<HpPersonHouseStatistics> trendR = crowdSituationApiService.geteveryYearTrendR();
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("fenLi", fenLi);
        resultObj.put("noFenLi", noFenLi);
        resultObj.put("trendH", trendH);
        resultObj.put("trendR", trendR);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 流动人口-当月来沪人员及同环比
     */
    @RequestMapping("getFloatingPopulation")
    public void getFloatingPopulation(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String key = "来沪人员";
        String key1 = "境外人员";
        Integer laiHu = crowdSituationApiService.getLaiHu(key);
        Integer jingWai = crowdSituationApiService.getLaiHu(key1);

        Integer lastYearLH = crowdSituationApiService.getLaiHuTb(key);
        Integer lastYearJW = crowdSituationApiService.getLaiHuTb(key1);
        //同比
        Double laiHuTb = Double.valueOf(lastYearLH) / Double.valueOf(laiHu) - 1;
        Double jingWaiTb = Double.valueOf(lastYearJW) / Double.valueOf(laiHu) - 1;
        Integer lastMonthLH = crowdSituationApiService.getLaiHuHb(key);
        Integer lastMonthJW = crowdSituationApiService.getLaiHuHb(key1);
        //环比
        Double laiHuHb = Double.valueOf(lastMonthLH) / Double.valueOf(laiHu) - 1;
        Double jingWaiHb = Double.valueOf(lastMonthJW) / Double.valueOf(laiHu) - 1;
        String nowMaxCountByStreetLH = crowdSituationApiService.getNowMaxCountByStreet(key);
        String nowMaxCountByStreetJW = crowdSituationApiService.getNowMaxCountByStreet(key1);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("laiHu", laiHu);
        resultObj.put("laiHuTb", laiHuTb);
        resultObj.put("laiHuHb", laiHuHb);
        resultObj.put("nowMaxCountByStreetLH", nowMaxCountByStreetLH);
        resultObj.put("jingWai", jingWai);
        resultObj.put("jingWaiTb", jingWaiTb);
        resultObj.put("jingWaiHb", jingWaiHb);
        resultObj.put("nowMaxCountByStreetLH", nowMaxCountByStreetLH);
        resultObj.put("nowMaxCountByStreetJW", nowMaxCountByStreetJW);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 流动人口-当月来沪人员-境外人员趋势
     */
    @RequestMapping("getFloatingPopulationTrend")
    public void getFloatingPopulationTrend(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String key = "来沪人员";
        String key1 = "境外人员";
        List<HpSyrkAgeDistribute> JW = crowdSituationApiService.getFloatingPopulationTrend(key);
        List<HpSyrkAgeDistribute> LH = crowdSituationApiService.getFloatingPopulationTrend(key1);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("JW", JW);
        resultObj.put("LH", LH);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 流动人口-当月来沪人员-境外人员 按照街道分布
     */
    @RequestMapping("getFloatingPopulationByStreet")
    public void getFloatingPopulationByStreet(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String key = "来沪人员";
        String key1 = "境外人员";
        List<HpPersonHouseStatistics> LH = crowdSituationApiService.getFloatingPopulationByStreet(key);
        List<HpPersonHouseStatistics> JW = crowdSituationApiService.getFloatingPopulationByStreet(key1);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("JW", JW);
        resultObj.put("LH", LH);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 人口结构-性别年龄-月份字典
     */
    @RequestMapping("getMonthGenderByAge")
    public void getMonthGenderByAge(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        List<String> month = crowdSituationApiService.getMonthGenderByAge();
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("month", month);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 人口结构-性别年龄结构
     */
    @RequestMapping("getGenderByAge")
    public void getGenderByAge(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);
        String year = jsonObject.getString("year");
        List<HpSyrkGender> man = crowdSituationApiService.getGenderByAgeMan(year);
        List<HpSyrkGender> woman = crowdSituationApiService.getGenderByAgeWoman(year);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("man", man);
        resultObj.put("woman", woman);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 疫情专题-复工企业详情
     */
    @RequestMapping("getReworkInfo")
    public void getReworkInfo(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        //
        List<ReworkInfo> info = crowdSituationApiService.getReworkInfo();

        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("info", info);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 疫情专题 ---疫苗接种人数
     */
    @RequestMapping("vaccinumPersonCount")
    @ResponseBody
    public Object vaccinumPersonCount() throws Exception {
        // 创建Httpclient对象
        CloseableHttpClient httpclient = HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();
        // 创建http POST请求
        HttpPost httpPost = new HttpPost("http://172.82.2.1/edc/rest/VaccinumData/gettotalsum");
        CloseableHttpResponse response = null;
        JSONObject resultObj = new JSONObject();
        try {
            // 执行请求
            response = httpclient.execute(httpPost);
            System.out.println(response.getStatusLine());
            // 判断返回状态是否为200
            if (response.getStatusLine().getStatusCode() == 200) {
                resultObj.put("error_code", 0);
                resultObj.put("error_msg", "获取成功");
                JSONArray array = JSONArray.parseArray(EntityUtils.toString(response.getEntity(), "UTF-8"));
                resultObj.put("data", array.get(0));
                return  resultObj;
            }
            resultObj.put("error_code", -1);
            resultObj.put("error_msg", "获取阿里接口异常,异常code:" + response.getStatusLine().getStatusCode());
            resultObj.put("data", "");
        }catch(Exception e){
            logger.error("获取阿里接口异常,异常信息:" + e);
            resultObj.put("error_code", -1);
            resultObj.put("error_msg", "获取阿里接口异常!");
            resultObj.put("data", "");
        }finally {
            if (response != null) {
                try {
                    response.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            try {
                httpclient.close();
            } catch (IOException e) {
                    e.printStackTrace();
            }
        }
        return resultObj;
    }


    /**
     * 人口结构-性别老龄化年龄结构
     */
    @RequestMapping("getAgingByAge")
    public void getAgingByAge(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        //60以上
        List<HpSyrkAgeDistribute> sixtyUp = crowdSituationApiService.getSixtyUp();
        //66以上
        List<HpSyrkAgeDistribute> sixtySixUp = crowdSituationApiService.getSixtySixUp();
        //0-6
        List<HpSyrkAgeDistribute> oneToSix = crowdSituationApiService.getOneToSix();
        //7-14
        List<HpSyrkAgeDistribute> sevenToFourteen = crowdSituationApiService.getSevenToFourteen();
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("sixtyUp", sixtyUp);
        resultObj.put("sixtySixUp", sixtySixUp);
        resultObj.put("oneToSix", oneToSix);
        resultObj.put("sevenToFourteen", sevenToFourteen);

        responseData(resultObj.toString(), resp);
    }

    /**
     * 南京东路街道人户情况及最近一年的趋势图
     */
    @RequestMapping("getNdStreetByType")
    public void getNdStreetByType(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);
        String street = jsonObject.getString("street");
        int RZHBZ = crowdSituationApiService.getRZHBZ(street);
        int HZRBZ = crowdSituationApiService.getHZRBZ(street);
        int RZHZ = crowdSituationApiService.getRZHZ(street);
        int QXBM = crowdSituationApiService.getQXBM(street);
        List<HpPersonHouseStatistics> trend = crowdSituationApiService.getNdStreetByType(street);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("RZHBZ", RZHBZ);
        resultObj.put("HZRBZ", HZRBZ);
        resultObj.put("RZHZ", RZHZ);
        resultObj.put("QXBM", QXBM);
        resultObj.put("trend", trend);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 人户一致
     */
    @RequestMapping("getRenHuYiZhi")
    public void getRenHuYiZhi(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        //上月
        List<HpPersonHouseStatistics> lastMonth = crowdSituationApiService.getCountByStreet();
        HpPersonHouseStatistics hpPersonHouseStatistics = new HpPersonHouseStatistics();
        Integer lastCount = crowdSituationApiService.getLastCount();
        hpPersonHouseStatistics.setSz(lastCount);
        hpPersonHouseStatistics.setJd("全区");
        lastMonth.add(hpPersonHouseStatistics);
        //本月
        List<HpPersonHouseStatistics> nowMonth = crowdSituationApiService.getNowCountByStreet();
        HpPersonHouseStatistics hp = new HpPersonHouseStatistics();
        Integer nowCount = crowdSituationApiService.getNowCount();
        hp.setSz(nowCount);
        hp.setJd("全区");
        nowMonth.add(hp);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("lastMonth", lastMonth);
        resultObj.put("nowMonth", nowMonth);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 电招电牌列表
     */
    @RequestMapping(value = "/getAllHpDianZhaoDianPaiInfo")
    public void getAllHpDianZhaoDianPaiInfoByStreet(HttpServletRequest req, HttpServletResponse resp) throws Exception {

        JSONObject resultObj = new JSONObject();
        JSONObject resultJson = new JSONObject();
        LogFactory.getLog(this.getClass()).info("------getAllHpDianZhaoDianPaiInfo-----start-------");
        String page = req.getParameter("page");
        String key = req.getParameter("key");
        List<SysShopRecruitStreet> listSysShopRecruitStreet = laoXiMenApiService.getAllHpDianZhaoDianPaiInfo(page, key, Constants.OFFSET);
        for (SysShopRecruitStreet sr : listSysShopRecruitStreet) {
            sr.setImageurl("http://172.82.4.51:8080/images/" + sr.getSerial_number() + "_simple.jpg");
        }
        Integer count = laoXiMenApiService.getShopCount(key);
//        for (SysShopRecruitStreet ss : listSysShopRecruitStreet) {
//            double[] map = MapUtil.bd09towgs84(Double.parseDouble(ss.getLng()), Double.parseDouble(ss.getLat()));
//            ss.setLng(map[0] + "");
//            ss.setLat(map[1] + "");
////            List<SysShopSignageStreet> listSysShopSignageStreet=laoXiMenApiService.getListSysShopSignageStreetByNumber(ss.getSerial_number());
////            ss.setListSysShopSignageStreet(listSysShopSignageStreet);
//        }

        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", listSysShopRecruitStreet);
        resultObj.put("count", count);
        responseData(resultObj.toString(), resp);

    }

    /**
     * 老西门增加店招店牌信息
     */
    @Transactional
    @RequestMapping(value = "addHpDianZhaoDianPaiInfo", method = RequestMethod.POST)
    public void addHpDianZhaoDianPaiInfo(SysShopRecruitStreet sr, HttpServletResponse resp, @RequestParam(value = "image") MultipartFile image, @RequestParam(value = "image_simple") MultipartFile image_simple) throws Exception {
        JSONObject resultObj = new JSONObject();
        if (sr != null && (image == null || image_simple == null)) {
            resultObj.put("error_code", 201);
            resultObj.put("error_msg", "上传图片为空，请选择图片");
        }
        HttpClient client = new DefaultHttpClient();
        String number = laoXiMenApiService.findHpDianZhaoDianPaiInfo(sr.getSerial_number());
        if (number != null) {
            resultObj.put("error_code", 202);
            resultObj.put("error_msg", "该编号已存在，请检查编号");
            responseData(resultObj.toString(), resp);
        } else {
            try {
                String pic_path;
                //上传
                String tomcat_path = System.getProperty("catalina.home");
                pic_path = tomcat_path + "/image/";
                if (sr.getSerial_number() == null) {
                    sr.setSerial_number("error");
                }
                File imageFile = new File(pic_path + sr.getSerial_number() + ".jpg");
                File imageFile_simple = new File(pic_path + sr.getSerial_number() + "_simple.jpg");
                if (image != null && image_simple != null) {
                    image.transferTo(imageFile);
                    image_simple.transferTo(imageFile_simple);
                }
                HttpGet get = new HttpGet("http://api.map.baidu.com/geocoder?address=" + sr.getUnit_adress() + "&output=json&key=PyLa5E6K6BEGI0euwz1s9dWc");

                HttpResponse response = client.execute(get);
                JSONObject jo = null;
                JSONObject jb = null;
                JSONObject locationjson = null;
                if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                    // 解析数据
                    String data = EntityUtils.toString(response.getEntity(), Charsets.UTF_8);
                    if (null != data) {
                        jo = JSONObject.parseObject(data);
                        if (jo.get("status").equals("OK")) {
                            jb = jo.getJSONObject("result");
                            locationjson = jb.getJSONObject("location");
                            double[] map = MapUtil.bd09towgs84(Double.valueOf(locationjson.getString("lng")), Double.valueOf(locationjson.getString("lat")));
                            sr.setUnit_adress(String.valueOf(map[0]));
                            sr.setUnit_adress(String.valueOf(map[1]));
                        }
                    }
                }
                laoXiMenApiService.addHpDianZhaoDianPaiInfo(sr);
                resultObj.put("error_code", 0);
                resultObj.put("path", pic_path + sr.getSerial_number() + ".jpg");
                resultObj.put("error_msg", "上传成功");
                resultObj.put("sr", sr);
                responseData(resultObj.toString(), resp);
            } catch (Exception e) {
                e.printStackTrace();
                resultObj.put("error_msg", "上传失败");
                resultObj.put("data", e.getStackTrace());
                resultObj.put(" sr.getSerial_number()", sr.getSerial_number());
                resultObj.put("sr.getImage()", image);
                resultObj.put("sr", sr);
                resultObj.put("Exception", e);
                responseData(resultObj.toString(), resp);
            }
        }

    }

    /**
     * 老西门修改店招店牌信息
     */
    @Transactional
    @RequestMapping(value = "updateHpDianZhaoDianPaiInfo", method = RequestMethod.POST)
    public void updateHpDianZhaoDianPaiInfo(SysShopRecruitStreet sr, @RequestParam(required = false, value = "image") MultipartFile image, @RequestParam(required = false, value = "image_simple") MultipartFile image_simple, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        if (sr != null) {
            resultObj.put("error_code", 201);
            resultObj.put("error_msg", "数据为空，请联系管理员");
            responseData(resultObj.toString(), resp);
        }
        HttpClient client = new DefaultHttpClient();
        try {
            String pic_path;
            //上传,重复则覆盖
            String tomcat_path = System.getProperty("catalina.home");
            pic_path = tomcat_path + "/image/";
            if (sr.getSerial_number() == null) {
                sr.setSerial_number("error");
            }
            File imageFile = new File(pic_path + sr.getSerial_number() + ".jpg");
            File imageFile_simple = new File(pic_path + sr.getSerial_number() + "_simple.jpg");
            if (image != null && image_simple != null) {
                image.transferTo(imageFile);
                image_simple.transferTo(imageFile_simple);
            }
            HttpGet get = new HttpGet("http://api.map.baidu.com/geocoder?address=" + sr.getUnit_adress() + "&output=json&key=PyLa5E6K6BEGI0euwz1s9dWc");

            HttpResponse response = client.execute(get);
            JSONObject jo = null;
            JSONObject jb = null;
            JSONObject locationjson = null;
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                // 解析数据
                String data = EntityUtils.toString(response.getEntity(), Charsets.UTF_8);
                if (null != data) {
                    jo = JSONObject.parseObject(data);
                    if (jo.get("status").equals("OK")) {
                        jb = jo.getJSONObject("result");
                        locationjson = jb.getJSONObject("location");
                        double[] map = MapUtil.bd09towgs84(Double.valueOf(locationjson.getString("lng")), Double.valueOf(locationjson.getString("lat")));
                        sr.setUnit_adress(String.valueOf(map[0]));
                        sr.setUnit_adress(String.valueOf(map[1]));
                    }
                }
            }
            laoXiMenApiService.updateHpDianZhaoDianPaiInfo(sr);
            resultObj.put("error_code", 0);
            resultObj.put("path", pic_path + sr.getSerial_number() + ".jpg");
            resultObj.put("error_msg", "上传成功");
            resultObj.put("sr", sr);
            responseData(resultObj.toString(), resp);
        } catch (Exception e) {
            e.printStackTrace();
            resultObj.put("error_msg", "上传失败");
            resultObj.put("data", e.getStackTrace());
            resultObj.put(" sr.getSerial_number()", sr.getSerial_number());
            resultObj.put("sr.getImage()", image);
            resultObj.put("sr", sr);
            resultObj.put("Exception", e);
            responseData(resultObj.toString(), resp);
        }
    }

    /**
     * 老西门删除店招店牌信息
     */
    @Transactional
    @RequestMapping(value = "deleteHpDianZhaoDianPaiInfo", method = RequestMethod.POST)
    public void deleteHpDianZhaoDianPaiInfo(@RequestParam(value = "id") String id, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        laoXiMenApiService.deleteHpDianZhaoDianPaiInfo(id);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);
    }

    /**
     * 老西门登录
     */
    @RequestMapping("login")
    public void getLogin(@RequestParam(value = "username", required = false) String username, @RequestParam(value = "password", required = false) String password, @RequestParam(value = "phone", required = false) String phone, HttpServletResponse resp) {
        try {
            JSONObject resultObj = new JSONObject();
            LxmSysUserAdmin SysUser = new LxmSysUserAdmin();
            if (username != null && password != null) {
                SysUser = laoXiMenApiService.getUserInfo(username, password);
                if (SysUser == null) {
                    resultObj.put("error_code", 201);
                    resultObj.put("error_msg", "用户名或密码错误，请重新登录");
                }
            }
            //忘记密码，手机号验证
            if (phone != null) {
                SysUser = laoXiMenApiService.getUserInfoByPhone(phone);
                if (SysUser == null) {
                    resultObj.put("error_code", 202);
                    resultObj.put("error_msg", "手机号验证失败，请联系管理员");
                }
            }
            if (SysUser != null) {
                SysUser.setToken("token_0");

                resultObj.put("error_code", 0);
                resultObj.put("error_msg", "登录成功");
                resultObj.put("user", SysUser);
            }
            responseData(resultObj.toString(), resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 修改密码
     */
    @RequestMapping("modifyPassword")
    public void modifyPassword(@RequestParam(required = false) String username, @RequestParam(required = false) String password, @RequestParam(required = false) String newPassword, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        if (username != null && password != null) {
            LxmSysUserAdmin isP = laoXiMenApiService.getUserPassword(password, username);
            if (isP == null) {
                resultObj.put("error_code", 201);
                resultObj.put("error_msg", "验证失败，请重新验证");
                responseData(resultObj.toString(), resp);
            } else {
                resultObj.put("error_code", 0);
                resultObj.put("error_msg", "验证成功");
                responseData(resultObj.toString(), resp);
            }
        }
        if (username != null && newPassword != null) {
            laoXiMenApiService.updatePassword(newPassword, username);
            resultObj.put("error_code", 0);
            resultObj.put("error_msg", "修改成功，请重新登录！");
            responseData(resultObj.toString(), resp);
        }
    }

    /**
     * 隐患店招信息的查询
     */
    @RequestMapping("getSysSignageErrorListByType")
    public void getSysSignageErrorListByType(@RequestParam(value = "address") String address, @RequestParam(value = "page") Integer page, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        List<LxmSignageError> ls = laoXiMenApiService.getSysSignageErrorListByType(address, page, Constants.OFFSET);
        for (LxmSignageError l : ls) {
            l.setImageurl("http://172.82.4.51:8080/images/" + l.getNumber() + "_simple.jpg");
            if (l.getRectify_number() != null) {
                l.setImageurl2("http://172.82.4.51:8080/images/" + l.getRectify_number() + "_simple.jpg");
            }
        }
        int count = laoXiMenApiService.getSignageError(address, page, Constants.OFFSET);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", ls);
        resultObj.put("count", count);
        responseData(resultObj.toString(), resp);
    }

    /***添加隐患店招信息*/
    @RequestMapping("addSysSignageError")
    public void addSysSignageError(LxmShopError sr, @RequestParam(value = "image") MultipartFile image, @RequestParam(value = "image_simple") MultipartFile image_simple, @RequestParam(required = false, value = "recruit") MultipartFile recruit, @RequestParam(required = false, value = "recruit_simple") MultipartFile recruit_simple, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        if (sr != null && (image == null || image_simple == null)) {
            resultObj.put("error_code", 201);
            resultObj.put("error_msg", "上传图片为空，请选择图片");
            responseData(resultObj.toString(), resp);
        }
        HttpClient client = new DefaultHttpClient();
        String number = laoXiMenApiService.findSysSignageError(sr.getNumber());
        if (number != null) {
            resultObj.put("error_code", 202);
            resultObj.put("error_msg", "该编号已存在，请检查编号");
            responseData(resultObj.toString(), resp);
        } else {
            try {
                String pic_path;
                //上传
                String tomcat_path = System.getProperty("catalina.home");
                pic_path = tomcat_path + "/image/";
                if (sr.getNumber() == null) {
                    sr.setNumber("error");
                }
                File imageFile = new File(pic_path + sr.getNumber() + ".jpg");
                File recruitFile = new File(pic_path + sr.getRectify_number() + ".jpg");
                File imageFile_simple = new File(pic_path + sr.getNumber() + "_simple.jpg");
                File recruit_simpleFile = new File(pic_path + sr.getRectify_number() + "_simple.jpg");
                if (image != null && image_simple != null) {
                    image.transferTo(imageFile);
                    image_simple.transferTo(imageFile_simple);
                }
                if ((recruit != null && recruit_simple != null)) {
                    recruit.transferTo(recruitFile);
                    recruit_simple.transferTo(recruit_simpleFile);
                }


                if (sr.getReview_result().equals("已整改")) {
                    sr.setType("0");
                } else {
                    sr.setType("1");
                }
                HttpGet get = new HttpGet("http://api.map.baidu.com/geocoder?address=" + sr.getAddress() + "&output=json&key=PyLa5E6K6BEGI0euwz1s9dWc");

                HttpResponse response = client.execute(get);
                JSONObject jo = null;
                JSONObject jb = null;
                JSONObject locationjson = null;
                if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                    // 解析数据
                    String data = EntityUtils.toString(response.getEntity(), Charsets.UTF_8);
                    if (null != data) {
                        jo = JSONObject.parseObject(data);
                        if (jo.get("status").equals("OK")) {
                            jb = jo.getJSONObject("result");
                            locationjson = jb.getJSONObject("location");
                            double[] map = MapUtil.bd09towgs84(Double.valueOf(locationjson.getString("lng")), Double.valueOf(locationjson.getString("lat")));
                            sr.setX(String.valueOf(map[0]));
                            sr.setY(String.valueOf(map[1]));
                        }
                    }
                }
                laoXiMenApiService.addSysSignageError(sr);

                resultObj.put("error_code", 0);
                resultObj.put("path", pic_path + sr.getNumber() + ".jpg");
                resultObj.put("error_msg", "上传成功");
                resultObj.put("sr", sr);
                responseData(resultObj.toString(), resp);
            } catch (Exception e) {
                e.printStackTrace();
                resultObj.put("error_msg", "上传失败");
                resultObj.put("data", e.getStackTrace());
                resultObj.put(" sr.getSerial_number()", sr.getNumber());
                resultObj.put("sr.getImage()", image);
                resultObj.put("sr", sr);
                resultObj.put("Exception", e);
                responseData(resultObj.toString(), resp);
            }
        }
    }

    /***修改隐患店招信息*/
    @RequestMapping("updateSysSignageError")
    public void updateSysSignageError(LxmShopError sr, @RequestParam(required = false, value = "image") MultipartFile image, @RequestParam(required = false, value = "image_simple") MultipartFile image_simple, @RequestParam(required = false, value = "recruit") MultipartFile recruit, @RequestParam(required = false, value = "recruit_simple") MultipartFile recruit_simple, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        if (sr != null) {
            resultObj.put("error_code", 201);
            resultObj.put("error_msg", "数据为空，请联系管理员");
        }
        HttpClient client = new DefaultHttpClient();
        try {

            String pic_path;
            //上传,重复则覆盖
            String tomcat_path = System.getProperty("catalina.home");
            pic_path = tomcat_path + "/image/";
            if (sr.getNumber() == null) {
                sr.setNumber("error");
            }
            File imageFile = new File(pic_path + sr.getNumber() + ".jpg");
            File imageFile_simple = new File(pic_path + sr.getNumber() + "_simple.jpg");
            File recruitFile = new File(pic_path + sr.getRectify_number() + ".jpg");
            File recruit_simpleFile = new File(pic_path + sr.getRectify_number() + "_simple.jpg");
            if (image != null && image_simple != null) {
                image.transferTo(imageFile);
                image_simple.transferTo(imageFile_simple);
            }
            if (recruit != null && recruit_simple != null) {
                recruit.transferTo(recruitFile);
                recruit_simple.transferTo(recruit_simpleFile);
            }
            resultObj.put("path", pic_path + sr.getNumber() + ".jpg");
            HttpGet get = new HttpGet("http://api.map.baidu.com/geocoder?address=" + sr.getAddress() + "&output=json&key=PyLa5E6K6BEGI0euwz1s9dWc");

            HttpResponse response = client.execute(get);
            JSONObject jo = null;
            JSONObject jb = null;
            JSONObject locationjson = null;
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                // 解析数据
                String data = EntityUtils.toString(response.getEntity(), Charsets.UTF_8);
                if (null != data) {
                    jo = JSONObject.parseObject(data);
                    if (jo.get("status").equals("OK")) {
                        jb = jo.getJSONObject("result");
                        locationjson = jb.getJSONObject("location");
                        double[] map = MapUtil.bd09towgs84(Double.valueOf(locationjson.getString("lng")), Double.valueOf(locationjson.getString("lat")));
                        sr.setX(String.valueOf(map[0]));
                        sr.setY(String.valueOf(map[1]));
                    }
                }
            }
            laoXiMenApiService.updateSysSignageError(sr);
            resultObj.put("error_code", 0);
            resultObj.put("error_msg", "上传成功");
            resultObj.put("sr", sr);
            responseData(resultObj.toString(), resp);
        } catch (Exception e) {
            e.printStackTrace();
            resultObj.put("error_msg", "上传失败");
            resultObj.put("data", e.getStackTrace());
            resultObj.put(" sr.getSerial_number()", sr.getNumber());
            resultObj.put("sr.getImage()", image);
            resultObj.put("sr", sr);
            resultObj.put("Exception", e);
            responseData(resultObj.toString(), resp);
        }
    }

    /***删除隐患店招信息*/
    @RequestMapping("deleteSysSignageError")
    public void deleteSysSignageError(@RequestBody LxmSignageError ls, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        laoXiMenApiService.deleteSysSignageError(ls);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);
    }

    /***添加用户信息*/

    @RequestMapping("addSysUserInfo")
    public void addSysUserInfo(@RequestBody LxmSysUserAdmin ls, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        LxmSysUserAdmin admin = laoXiMenApiService.findUserByUserName(ls.getUser_name());
        if (admin.getUser_name() != null) {
            resultObj.put("error_code", 202);
            resultObj.put("error_msg", "用户名已存在,请重新选择");
        } else {
            ls.setPassword("123456");
            laoXiMenApiService.addSysUserInfo(ls);
            resultObj.put("error_code", 0);
            resultObj.put("error_msg", "获取成功");
        }
        responseData(resultObj.toString(), resp);
    }

    /***查询用户信息*/
    @RequestMapping("findSysUserInfo")
    public void findSysUserInfo(@RequestParam(value = "key", required = false) String key, @RequestParam(value = "page") int page, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
//        if (key!=null) {
//            key = new String(key.getBytes("ISO-8859-1"), "UTF-8");
//        }
        List<LxmSysUserAdmin> list = laoXiMenApiService.findSysUserInfo(key, page, Constants.OFFSET);
        Integer count = laoXiMenApiService.getPageCount(key);

//        double  pageCount=Math.ceil(Double.valueOf(count)/Constants.OFFSET);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", list);
//        resultObj.put("pageCount", (int)pageCount);
        resultObj.put("count", count);
        responseData(resultObj.toString(), resp);
    }

    /***修改用户信息*/

    @RequestMapping("updateSysUserInfo")
    public void updateSysUserInfo(@RequestBody LxmSysUserAdmin ls, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        laoXiMenApiService.updateSysUserInfo(ls);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);
    }

    /***删除用户信息*/

    @RequestMapping("deleteSysUserInfo")
    public void deleteSysUserInfo(@RequestBody LxmSysUserAdmin ls, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        laoXiMenApiService.deleteSysUserInfo(ls);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);
    }

    /***查询检查记录表*/
    @RequestMapping("getExamineRecord")
    public void getExamineRecord(@RequestParam(value = "error_number") String error_number, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        List<LxmSysExamineRecord> lxmSysExamineRecord = laoXiMenApiService.getExamineRecord(error_number);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", lxmSysExamineRecord);
        responseData(resultObj.toString(), resp);
    }

    /***更新检查记录表*/
    @RequestMapping("updateExamineRecord")
    public void updateExamineRecord(@RequestBody LxmSysExamineRecord le, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        laoXiMenApiService.updateExamineRecord(le);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        responseData(resultObj.toString(), resp);
    }

    /**
     * 社会综治实有人口撒点
     */
    @RequestMapping("getPersonPoint")
    public void getPersonPoint(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        String str = getRequestBodyString(req);
        if (StringUtil.isEmpty(str)) {
            responseErrorData("json error", resp);
            return;
        }
        JSONObject jsonObject = JSONObject.parseObject(str);
        String i = jsonObject.getString("i");
        List<HpBasSyrkJzdz> hpBasSyrkJzdzs = personDataService.getPersonPoint(i);
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", hpBasSyrkJzdzs);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 少数名族撒点
     */
    @RequestMapping("getMinorityPersonPoint")
    public void getMinorityPersonPoint(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();
        List<HpBasSyrkJzdz> hpBasSyrkJzdzs = personDataService.getMinorityPersonPoint();
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", hpBasSyrkJzdzs);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 街道实时人口
     */
    @RequestMapping("getTimerPersonCountInfo")
    @ResponseBody
    public Object getTimerPersonCountInfo(){
        List<HpSyrkStreet> hpSyrkStreetList = personDataService.getHpSyrkStreetList();
        JSONObject resultObj = new JSONObject();
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("data", hpSyrkStreetList);
        return resultObj;
    }

    /**
     * 小型工程撒点
     */
    @RequestMapping("getXiaoGongChengByMysql")
    public void getXiaoGongChengByMysql(HttpServletRequest req, HttpServletResponse resp) throws Exception {
        JSONObject resultObj = new JSONObject();

        List<SysXiaoGongCheng> state = laoXiMenApiService.getXiaoGongChengByMysql();
        for (SysXiaoGongCheng sysXiaoGongCheng : state) {
            sysXiaoGongCheng.setOctober(sysXiaoGongCheng.getOctober());
        }
        List<SysXiaoGongCheng> projects = laoXiMenApiService.getXiaoGongChengProjectByMysql();
        for (SysXiaoGongCheng project : projects) {
            String s = project.getLocation().replaceAll("\\[", "");
            String s1 = s.replaceAll("]", "");
            String[] split = s1.split(",");
            project.setLocation_x(split[0]);
            project.setLocation_y(split[1]);
        }
        resultObj.put("error_code", 0);
        resultObj.put("error_msg", "获取成功");
        resultObj.put("state", state);
        resultObj.put("projects", projects);
        responseData(resultObj.toString(), resp);
    }

    /**
     * 从req中读取数据
     *
     * @param req
     * @return
     */
    private String getRequestBodyString(HttpServletRequest req) {
        StringBuilder builder = new StringBuilder();
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(req.getInputStream(), "utf-8"));
            String line;
            while ((line = br.readLine()) != null) {
                builder.append(line);
            }
        } catch (IOException e) {
            // e.printStackTrace();
            return null;
        }
        return builder.toString();
    }

    private void responseErrorData(String string, HttpServletResponse resp) throws Exception {
        // TODO Auto-generated method stub
        JSONObject resultObj = new JSONObject();
        resultObj.put("errorcode", 1);
        resultObj.put("message", string);
        responseData(resultObj.toString(), resp);
    }

    private void responseData(String string, HttpServletResponse resp) throws Exception {
        // TODO Auto-generated method stub
        responseDate("application/json;charset=UTF-8", string, resp);

    }

    private void responseDate(String contentType, String value, HttpServletResponse resp) throws Exception {
        resp.setContentType(contentType);
        resp.getWriter().write(value);
    }
}
